public with sharing class DependentDropDownController {

    public String selectedCandidate { get; set; }
    
    public String firstTime{ get; set; }

    
    
 public List<SelectOption> allPositions {get; set;}

 
 public List<SelectOption> allApplicationsForAPosition {get; set;}

 public List<SelectOption> allCandidatesForApplications{get; set;}
 
 public List<SelectOption> allReviewsForApplications {get; set;}

  
  public String selectedPosition  {get; set;}
  public String selectedApplication  {get; set;}
  
  public DependentDropDownController(){
    allPositions= new List<SelectOption> ();
    firstTime='1';
    
    allApplicationsForAPosition= new List<SelectOption>();

    allCandidatesForApplications= new List<SelectOption>();
    allReviewsForApplications= new List<SelectOption>();
    
    selectedPosition= StringUtils.EMPTY;
    selectedApplication= StringUtils.EMPTY;
    
    //fetchAllPositions
    
    fetchAllPositions();
    /*System.debug('>>>>>>>>>>>>>>>>>>>>>');
    for(SelectOption str: allPositions){
        System.debug('@@@ Label:= '+ str.getLabel() + '@@@ Value:= '+ str.getValue());
    }
     System.debug('<<<<<<<<<<<<<<<<<<<<<');*/
     
   
  }
  
  
  
  public void fetchAllPositions(){
    
    for (Position__c position: [Select position.name,position.id from Position__c position order by position.name]){
        allPositions.add(new SelectOption(position.Id,position.Name));
       
    }
     if(allPositions.isEmpty()){
        MessaageUtils.addErrorMessage('No Positions are available for Job' + selectedPosition );
    }
  }


    public void fetchAllApplicationsForAPosition(){
        allApplicationsForAPosition.clear();
        for (Job_Application__c jobApp: [Select ja.name,ja.id from Job_Application__c ja where ja.position__c =: selectedPosition]){
              
        allApplicationsForAPosition.add(new SelectOption(jobApp.Id,jobApp.Name));
    
    }
    if(allApplicationsForAPosition.isEmpty() ){
        MessaageUtils.addErrorMessage('No matching Job application exist for the position ' + selectedPosition );
    }
    
  }
  
  
   public void fetchAllReviewsForApplications(){
        allReviewsForApplications.clear();
        for (Review__c review : [Select review.name,review.id from Review__c review where review.Job_Application__c =: selectedApplication]){
            
        allReviewsForApplications.add(new SelectOption(review.Id,review.Name));
    
    }
    if(allReviewsForApplications.isEmpty()){
        MessaageUtils.addErrorMessage('No Review  exist for the Jobs ' + selectedApplication );
    }
    
  }
}